Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
My Function returns "[object Promise]" as result(after timeout). But when the function is used, the console is already logging the result (steamID) JS

I tried it without the timeout, without transfering the steamID into a string (both "Cannot send an empty message")an some more. But I haven't gotten any further for like 30 minutes.

(vanityURL = input)

My Function(The API is completly working):

const fetch = require("node-fetch");
const botconfig = require("../botconfig.json")

async function getSteamID(vanityURL) {

    const response = await fetch(`https://api.steampowered.com/ISteamUser/ResolveVanityURL/v1/?key=${botconfig.steamapikey}&vanityurl=${vanityURL}`);
    const data = await response.json();

    const listDataRaw = JSON.stringify(data);
    const listData = listDataRaw.toString();

    var steamID = listData.replace(/{"response":{"steamid":"|","success":1}}/g, "") // Filter
    console.log(steamID)

    return steamID;
}

module.exports = { getSteamID }

My test command:

const getSteamInfo = require('../functions/getSteamInfo');

module.exports.run = async (bot, message, args) => {
    var vanityURL = args.join(' ')


    const rawSteamID = getSteamInfo.getSteamID(vanityURL);

    await new Promise(r => setTimeout(r, 1000));
    let steamID = rawSteamID.toString();
    message.channel.send(steamID)



};

module.exports.command = {
    name: `test`
}

Thanks for help!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Just put "await" const rawSteamID = await getSteamInfo.getSteamID(vanityURL);

and see it is working

about 4 years ago · Juan Pablo Isaza Relatório

0

You forgot to await your call to getSteamInfo.getSteamID.

(You also forgot to await the call to message.channel.send so right now any errors thrown by it would turn into an unhandled rejection.)

const getSteamInfo = require('../functions/getSteamInfo');

module.exports.run = async (bot, message, args) => {
    const vanityURL = args.join(' ')

    const rawSteamID = await getSteamInfo.getSteamID(vanityURL)
    //                 ^^^^^

    const steamID = rawSteamID.toString() // not sure this is even needed...?
    await message.channel.send(steamID)
    //^^^
}

module.exports.command = {
    name: `test`
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda